package com.codeoss.framework.workflow.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.codeoss.framework.expression.Expression;
import com.codeoss.framework.expression.IScriptServiceStore;
import com.codeoss.framework.workflow.context.WorkflowContext;
import com.codeoss.framework.workflow.def.ServiceNodeDef;

@Service
public class ServiceNodeService extends AbstractNodeService{
	@Autowired
	private IScriptServiceStore scriptServiceStore;
	@Override
	@Transactional
	public void execute(WorkflowContext workflowContext) {
		 ServiceNodeDef  serviceNodeDef=(ServiceNodeDef)workflowContext.getNodeDef();
		 Expression expression=serviceNodeDef.getExecuteExpression();
		 if(expression!=null) {
			 Map<String,Object> bindingMap=new HashMap<String,Object>();
			 bindingMap.put("workflowContext", workflowContext);
			 scriptServiceStore.getScriptService(expression).eval(expression.getScript(), bindingMap);
		 }
		 super.execute(workflowContext);
	}
}
